package gameoflife;

import static java.lang.Math.abs;

public class Cell {

	private final int x;
	private final int y;

	public Cell(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public boolean isNeighbourOf(int x, int y) {
		if (equals(x, y))
			return false;
		if (isHorizontalDistanceToBig(x))
			return false;
		if (isVerticalDistanceToBig(y))
			return false;
		return true;
	}

	public boolean equals(int x, int y) {
		return this.x == x && this.y == y;
	}

	private boolean isHorizontalDistanceToBig(int x) {
		return abs(this.x - x) > 1;
	}

	private boolean isVerticalDistanceToBig(int y) {
		return abs(this.y - y) > 1;
	}

	public int x() {
		return x;
	}

	public int y() {
		return y;
	}

}
